<?php
/**
 * Object Relational Persistence Mapping Class for table: patient_entry
 *
 * @package	com.clearhealth
 * @author	ClearHealth Inc.
 */
class PatientEntry extends ORDataObject {

	/**#@+
	 * Fields of table: patient_entry mapped to class members
	 */
	var $patient_entry_id		= '';
	var $patient_id		= '';
	var $ticket_id		= '';
	var $entry_time		= '';	
	var $receptionist_name		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'patient_entry';

	/**
	 * Primary Key
	 */
	var $_key = 'patient_entry_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'PatientEntry';

	/**
	 * Handle instantiation
	 */
	function PatientEntry() {
		parent::ORDataObject();
	}

	
	/**#@+
	 * Field: entry_time, time formatting
	 */
	function get_entry_time() {
		return $this->_getDate('entry_time');
	}
	function set_entry_time($date) {
		$this->_setDate('entry_time',$date);
	}
	/**#@-*/

	public function add($ticketId, $patientId, $receptionistName) {
		if ($this->isExist($ticketId)) {
			return;
		}
		
		$data = array(
			'ticket_id'	=> $ticketId,
			'patient_id'	=> $patientId,
			'receptionist_name'	=> $receptionistName);
		$this->populateArray($data);
		$this->persist();
				
		$this->_execute("UPDATE $this->_table SET entry_time = NOW() where patient_entry_id = " . $this->patient_entry_id);				
	}	

	private function isExist($ticketId) {
		$sql = "SELECT patient_entry_id from patient_entry where ticket_id = $ticketId";
		$res = $this->_execute($sql);
		if ($res && !$res->EOF) {
			return true;
		}
		return false;
	}
}
?>







